<?php
/**
 * XmuSlh, web platform of Student Association Federation of Xiamen University
 * 
 * Rewritting one or some pages of StatusNet. 
 * To get the original version, please visit <http://status.net/>.
 * 
 * StatusNet, the distributed open-source microblogging tool
 * 
 * LICENCE: This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU Affero General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU Affero General Public License for more details.
 *
 * You should have received a copy of the GNU Affero General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * The setup procedure. Something initialized here and prepare for further
 * execution.
 * Most referred to the '/lib/common.php'
 * 
 * 初始化一些必要的引用和定义, 为进一步的php解释执行做准备.
 * 
 * @author		ytukie <ytukie@gmail.com>
 * @version		0.1
 */

// XmuSlh only.
if ( !defined('XMUSLH')) { exit(1); }

// Some Definitions
// Avatar
define('AVATAR_PROFILE_SIZE', 96);
define('AVATAR_STREAM_SIZE', 48);
define('AVATAR_MINI_SIZE', 24);
// ...

// append our extlib dir as the last-resort place to find libs
set_include_path(get_include_path() . PATH_SEPARATOR . INSTALLDIR . '/extlib/');

/**
 * The autoloaders.
 * This function is registered to be called while the system could not find a 
 * stuff(class, definition, action or something). It would help to load the related
 * file dynamically in such a fancy function.
 * 
 * Not preparing to use it... For lots of inefficient operations.
 */
function slh_autoload_sn($cls)
{
	// 1st the '/classes/'	Object-Oriented specific class, no need for slh_
	if (file_exists(INSTALLDIR . '/classes/' . $cls . '.php')) {
		require_once(INSTALLDIR . '/classes/' . $cls . '.php');
	}
	// 2nd the '/lib/  		adds slh_
	else if (file_exists(INSTALLDIR . '/lib/slh_' . strtolower($cls) . '.php')) {
		require_once(INSTALLDIR . '/lib/slh_' . strtolower($cls) . '.php');
	}
	// 3rd the '/action/'	adds slh_
	else if (mb_substr($cls, -6) == 'Action' &&
			 file_exists(INSTALLDIR . '/actions/slh_' . strtolower(mb_substr($cls, 0, -6)) . '.php')) {
		require_once(INSTALLDIR . '/actions/slh_' . strtolower(mb_substr($cls, 0, -6)) . '.php');	 	
	}
}

spl_autoload_register('slh_autoload_sn');

// Global configuration object
require_once('PEAR.php');
require_once('DB/DataObject.php');
require_once('DB/DataObject/Cast.php');

// For language.
// require_once(INSTALLDIR . '/lib/landuage.php');

// For plugins, ignoring currently.
/*
require_once(INSTALLDIR . '/lib/event.php');
require_once(INSTALLDIR . '.lib/plugin.php');

function addPlugins($name, $attrs = null)
{
	// return ::addPlugin($name, $attrs);
	return;
}
*/

// XXX: how many of these could be auto-loaded on use?
// XXX: note that these files should not use config options
// at compile time since DB config options are not yet loaded.

require_once 'Validate.php';
require_once 'markdown.php';

// FIXME: mail.php subs.php clientexception.php serverexception.php
require_once INSTALLDIR . '/lib/slh_util.php';
require_once INSTALLDIR . '/lib/slh_action.php';
require_once INSTALLDIR . '/lib/xmuslh.php';

try {
	XmuSlh::init(@$server, @$path, @$conffile);
} catch (NoConfigException $e) {
	// FIXME: Nice message style.
	echo 'No configuration.';
}
